package com.woniu.service.impl;

import com.woniu.controller.form.CheckList;
import com.woniu.controller.form.ProductForm;
import com.woniu.model.EProduct;
import com.woniu.dao.EProductMapper;
import com.woniu.model.Page;
import com.woniu.service.IEProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 拍品表 服务实现类
 * </p>
 *
 * @author Kevin Kwok
 * @since 2021-04-16
 */
@Service
public class EProductServiceImpl extends ServiceImpl<EProductMapper, EProduct> implements IEProductService {

    @Resource
    private EProductMapper productMapper;


    @Override
    public List<ProductForm> showAllCurrent(int pageIndex, int pagesize) {
        //当前页的查询起始位置
        int start = (pageIndex - 1) * pagesize;
        List<ProductForm> productForms = productMapper.showAllCurrent(start, pagesize);
        return productForms;
    }

    //封装page对象，用来给分页做准备
    @Override
    public Page getPageInfo(int pageIndex, int pageSize) {
        Page page = new Page();
        page.setPageIndex(pageIndex);
        int i = productMapper.countAllRecords();
        System.out.println("总条数："+i);
        page.setDataCount(i);
        page.setPageSize(pageSize);
        page.setPageCount(i % pageSize == 0 ? i / pageSize : i / pageSize + 1);
        return page;
    }

    @Override
    public List<CheckList> queryAll() {
        List<CheckList> checkLists = productMapper.queryAll();
        return checkLists;
    }

    @Override
    public int checkPass(int productId) {
        int i = productMapper.checkPass(productId);
        return i;
    }

    @Override
    public int checkRefuse(int productId) {
        int i = productMapper.checkRefuse(productId);
        return i;
    }
}
